﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StockFinder.Model;
using System.IO;

namespace StockFinder.Services.FileManagement
{
    /// <summary>
    /// Writes a list of symbols to a text file
    /// </summary>
    public class SymbolListToTextFileWriter
    {
        public void Write(List<Symbol> symbols, string filename)
        {
            StringBuilder fileBuilder = new StringBuilder();

            //check there are symbols
            if (symbols.Count > 0)
            {
                //loop the symbols
                foreach (Symbol symbol in symbols)
                {
                    //add symbol name to list
                    fileBuilder.AppendLine(symbol.Name);
                }

                //write the file contents
                File.WriteAllText(filename, fileBuilder.ToString());
            }
        }

        public void Write(List<IBDRatings> ratings, string filename)
        {
            StringBuilder fileBuilder = new StringBuilder();

            //check there are symbols
            if (ratings.Count > 0)
            {
                //loop the symbols
                foreach (IBDRatings rating in ratings)
                {
                    //add symbol name to list
                    fileBuilder.AppendLine(rating.Symbol);
                }

                //write the file contents
                File.WriteAllText(filename, fileBuilder.ToString());
            }
        }

        public void Write(List<string> symbolsNames, string filename)
        {
            StringBuilder fileBuilder = new StringBuilder();

            //check there are symbols
            if (symbolsNames.Count > 0)
            {
                //loop the symbols
                foreach (string symbol in symbolsNames)
                {
                    //add symbol name to list
                    fileBuilder.AppendLine(symbol);
                }

                //write the file contents
                File.WriteAllText(filename, fileBuilder.ToString());
            }
        }
    }
}
